#include <string>
#include "CGlobal.h"
#include "CServerMessagePacket.h"

CServerMessagePacket::CServerMessagePacket() {
	this->type = 0x4D;
	this->size = 0x0E;

	memset(this->data, 0, sizeof(this->data));
	// Unknowns
	data[0x04-0x04] = 0x01;
	data[0x05-0x04] = 0x01;
	data[0x06-0x04] = 0x01;
	data[0x07-0x04] = 0x02;
	data[0x08-0x04] = 0x6A;
	data[0x09-0x04] = 0x21;
	data[0x0A-0x04] = 0x24;
	data[0x0B-0x04] = 0x4A;

	unsigned long length = 0;
	length = (unsigned long) strlen(CGlobal::serverMessage);
	memcpy(data+0x0C-0x04,&length,4);
	memcpy(data+0x14-0x04,&length,4);
	for(unsigned short count = 0; count < length; count++ ) {
		unsigned short test = 0x0000;
		memcpy(&test, &CGlobal::serverMessage[count], 2);
		//  0x0A0D = next line for packet
		//  \n = 0x6E5C in hex
		if(test == 0x6E5C) {
			test = 0x0A0D;
			memcpy(data+0x18-0x04+count, &test, 2);
			count++;
		} else {
			data[0x18-0x04+count] = CGlobal::serverMessage[count];
		}
	}
	this->size += (unsigned char)(((length/4)+1)*4);
}

CServerMessagePacket::~CServerMessagePacket() {

}
